package com.example;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(path = "/create")
public class CreateController {
    @Autowired
    private UserRepository userRepository;

    @PostMapping(path = "/index")
    public @ResponseBody String add(@RequestParam String name) {
        // 实例化记录对象
        User user = new User();
        // 设置记录的属性值
        user.setName(name);
        // 保存记录
        userRepository.save(user);
        // 响应结果
        return "Saved!";
    }
}
